<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Express extends MY_Controller {
	
	function __construct(){
		parent::__construct();
		$this->load->model('order/ExpressModel', '' , true);
	}
	
	/*
	 * 快递公司管理
	 */
	function index($index=1,$size=10){
		$view_data = $this->_data($index,$size);
		$this->load->view('order/express/index',$view_data);
	}
	
	/*
	 * ajax 返回快递公司列表
	 */
	function data_list($index=1,$size=10){
		$view_data = $this->_data($index,$size);
		$this->load->view('order/express/data_list',$view_data);
	}
	
	function _data($index=1,$size=20) {
		$result = $this->ExpressModel->select($index,$size);
		$data['list'] = $result['data'];
		$this->load->library('pagination');
		$data['pages'] = $this->pagination->get_pages(base_url().index_page().'/order/express/index',$result['total'],$size,$index);
		return $data;
	}
	/*
	 * exist 检测快递名称是否存在
	 */
	function exist($name) {
		$name = urldecode($name);
		$data['state'] = $this->ExpressModel->isExistName($name);
		$this->_output_json($data);
	}
	/*
	 * add 新增
	 * 
	 * $redirect=''
	 */
	function add() {
		$arr['name'] = $this->input->post('name',true);
		$arr['remark'] = $this->input->post('remark',true);
		$data['state'] = $this->ExpressModel->insert($arr);
		$data['message'] = $data['state'] > 0 ? '新增快递公司成功。':'新增快递公司失败！';
		$this->_output_json($data);
	}
	
	function show_edit($id) {
		$view_data['o'] = $this->ExpressModel->selectById($id);
		$view_data['action'] = 'edit';
		$view_data['view'] = 'order/express/add_edit';
		$this->load->view('view',$view_data);
	}
	
	function edit() {
		$data['state'] = $this->ExpressModel->update($_POST);
		$data['message'] = $data['state'] > 0 ? '编辑快递公司成功。':'编辑快递公司失败！';
		$this->_output_json($data);
	}
	function delete($id) {
		$data['state'] = $this->ExpressModel->delete($id);
		$data['message'] = $data['state'] ? '删除快递公司成功。':'删除快递公司失败！';	
		$this->_output_json($data);
	}

}
?>